import 'dart:convert';

import 'package:built_value/built_value.dart';
import 'package:built_value/serializer.dart';
import 'package:schedule_self_client/common/serializers.dart';

part 'task.g.dart';

abstract class Task implements Built<Task, TaskBuilder> {
  Task._();

  factory Task([void Function(TaskBuilder) updates]) = _$Task;

  int get id;

  String get name;

  String get description;

  String get startTime;

  String get endTime;

  int get completeFlag;

  String? get completeTime;

  String toJson() {
    return jsonEncode(serializers.serializeWith(Task.serializer, this));
  }

  static Task? fromJson(String jsonString) {
    return serializers.deserializeWith(Task.serializer, jsonDecode(jsonString));
  }

  static Serializer<Task> get serializer => _$taskSerializer;

  bool isComplete() {
    return completeFlag == 1;
  }
}
